package getKthFromEnd;

public class Solution {
      public class ListNode {
      int val;
      ListNode next;
      ListNode(int x) { val = x; }
  }
    public ListNode getKthFromEnd(ListNode head, int k) {
          // 删除倒数第k个节点
        ListNode p1 = head;
        ListNode p2 = head;
        while (k>0) {
            p2 = p2.next;
            k--;
        }
        while (p2!=null) {
            p1 = p1.next;
            p2 = p2.next;
        }
        return p1;
    }
}
